package dnbW.entityW;

/**
 * Encapsulates a relationship between entities in a entity-relationship graph
 * @author truongbaquan
 */
public class Relationship {
    private IEntity entity1;

    public IEntity getEntity1() {
        return entity1;
    }

    private Cardinality cardinality1 = Cardinality.unknown;

    public Cardinality getCardinality1() {
        return cardinality1;
    }

    private IEntity entity2;

    public IEntity getEntity2() {
        return entity2;
    }

    private Cardinality cardinality2 = Cardinality.unknown;

    public Cardinality getCardinality2() {
        return cardinality2;
    }

    public Relationship(IEntity entity1, IEntity entity2) {
        this.entity1 = entity1;
        this.entity2 = entity2;
        entity1.addRelationship(entity2, this);
        entity2.addRelationship(entity1, this);
    }

    public Relationship(IEntity entity1, Cardinality cardinality1, IEntity entity2, Cardinality cardinality2) {
        this.entity1 = entity1;
        this.cardinality1 = cardinality1;
        this.entity2 = entity2;
        this.cardinality2 = cardinality2;
        entity1.addRelationship(entity2, this);
        entity2.addRelationship(entity1, this);
    }
}
